/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pruebareport;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Jose Carlos Palma
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }

        try {
            // TODO code application logic here
            System.getProperties().load(new FileInputStream("report.conf"));
        } catch (FileNotFoundException ex) {
            System.out.println("Error con report.conf: " + ex.getMessage());
            System.exit(1);
        } catch (IOException ex) {
            System.out.println("Error con report.conf: " + ex.getMessage());
            System.exit(1);
        }


        MainFrame.main(args);


    }

    public static void generarReporte() {
        File f = new File("newReport.jasper");

        System.out.println((f.exists() ? "" : "No ") + "Existe...!");

        try {
            JasperReport js = (JasperReport) JRLoader.loadObject(f);

            HashMap<String, Object> param = new HashMap<String, Object>();
            param.put("Nombre", "Jose Carlos Palma");

            JasperPrint jp = JasperFillManager.fillReport(js, param);

            JButton btn = new JButton("Fack");


            btn.setFocusable(false);
            btn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
            btn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
            

            JasperViewer jv = new JasperViewer(jp, false);
            
            
            JRootPane rp = (JRootPane) jv.getComponent(0);
            JPanel jpn = (JPanel) rp.getComponent(0);
            
            System.out.println(jpn.getLayout());
            //System.out.println("0: " + rp.getComponent(1));
            
            
            jv.setTitle("Titulo");
            jv.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
            jv.setVisible(true);


            //JasperReport jr =
        } catch (JRException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
